473,467 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

System.Web.HttpException: A DropDownList cannot have multiple items selected

I'm having such a problem with this DropDownList in a user control that is
posting back and throwing an error: System.Web.HttpException: A
DropDownList cannot have multiple items selected

<ASP:DROPDOWNLIST ID="lbCountriesWiz" ENABLEVIEWSTATE="true" FONT-SIZE="8pt"
ONSELECTEDINDEXCHANGED="ddlQueryProvinces"
AUTOPOSTBACK="True" RUNAT="server" WIDTH="150px"></ASP:DROPDOWNLIST>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then

Dim tempItem3 As New System.Web.UI.WebControls.ListItem
tempItem3.Text = "Chad"
tempItem3.Value = "TD"
tempItem3.Selected = False
Me.lbCountriesWiz.Items.Insert(0, tempItem3)

Dim tempItem2 As New System.Web.UI.WebControls.ListItem
tempItem2.Text = "Bosnia and Herzegovina"
tempItem2.Value = "BA"
tempItem2.Selected = False
Me.lbCountriesWiz.Items.Insert(0, tempItem2)

Dim tempItem As New System.Web.UI.WebControls.ListItem
tempItem.Text = "|--None Selected"
tempItem.Value = "0"
tempItem.Selected = False
lbCountriesWiz.Items.Insert(0, tempItem)

End If

End Sub

When a button in the same user control is pushed and then I reselect the
DropDownList, I don't get the error.

<ASP:BUTTON ID="btnAllCommunities"
ONCLICK="btnPopulateAllCommunities_OnClick" FONT-SIZE="8"
RUNAT="server" TEXT="All Communities" BORDERSTYLE="inset"></ASP:BUTTON>

Public Sub btnPopulateAllCommunities_OnClick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnAllCommunities.Click

'These simply fill some other listboxes

GetProvinces()
GetDistricts()
GetSubDistricts()
GetCommunities()

End Sub

When buttons (such as below) in the controling Page are pushed and then I
try to reselect the DropDownList, I get the error.

<ASP:BUTTON id="btn1" onclick="GetReport1_OnClick" RUNAT="server" TEXT="Get
report of" HEIGHT="20"
FONT-SIZE="10px"></ASP:BUTTON>

Sub GetReport1_OnClick(ByVal Sender As Object, ByVal e As System.EventArgs)

Try

dgSHA.Visible = False
dgShasSum.Visible = False
dgCommunity.Visible = True
dgCommunitiesSum.Visible = True
ShowButtons()


'pnlCommunitiesButtons.Visible = True

Dim _sqlStmtR1 As String
_sqlStmtR1 = "SELECT * FROM vwCommunities WHERE countryID = '" &
CType(Page,
_default1).chooseAdminUnitsWiz1.lbCountriesWiz.Sel ectedItem.Value & "' "

If ddlImpactLevel1.SelectedItem.Value <> "All" Then
_sqlStmtR1 = _sqlStmtR1 & " AND Impact = '" &
ddlImpactLevel1.SelectedItem.Value & "'"
End If
'_sqlStmtR1 = _sqlStmtR1 & " ORDER BY Community"

Dim myDataSetCommunities1 As New DataSet
Dim myDataAdapterCommunities1 As New SqlDataAdapter(_sqlStmtR1,
connection1.conString)
myDataAdapterCommunities1.Fill(myDataSetCommunitie s1,
"CommunitiesTmp1")
dgCommunity.DataSource =
myDataSetCommunities1.Tables("CommunitiesTmp1")
dgCommunity.DataBind()

CommunitiesWizSqlSumStatement(1)

Dim myDataSetCommunitiesSum As New DataSet
Dim myDataAdapterCommunitiesSum As New
SqlDataAdapter(_sqlStmtLbCommunitiesWizSum, connection1.conString)
myDataAdapterCommunitiesSum.Fill(myDataSetCommunit iesSum,
"CommunitiesSumTmp1")
dgCommunitiesSum.DataSource =
myDataSetCommunitiesSum.Tables("CommunitiesSumTmp1 ")
dgCommunitiesSum.DataBind()
RecordCount2.Text = ""
RecordCount3.Text = ""
RecordCount4.Text = ""
RecordCount5.Text = ""
RecordCount6.Text = ""

Dim RcdCount As Integer
Dim ResultCount As Integer
RcdCount =
myDataSetCommunities1.Tables("CommunitiesTmp1").Ro ws.Count.ToString()
ResultCount = RcdCount
RecordCount1.Text = RcdCount & " records"
RecordCountBottom.Text = RcdCount & " records"

Session("savedDataGridSql") = _sqlStmtR1
Session("dgType") = "Community"
Me.sortCriteria = "Community"
Me.sortDir = "ASC"
If Session("dgType") = "Community" Then
pnlCommunitiesButtons.Visible = True
pnlShasButtons.Visible = False
Else
pnlCommunitiesButtons.Visible = False
pnlShasButtons.Visible = True
End If


Catch ex As Exception
ExceptionManager.Publish(ex)
End Try
End Sub
Jul 25 '05 #1
1 6293
You've shown a lot of code, too much and too spread out to be too useful.
But the error speaks for itself, somewhere you are setting two selected
values to the dropdown and this isn't allowed. My guess is that it's
beeing set in the Page_Load and being set elsewhere on one of the many
button postbacks.... You'll simply need to debug and/or simplify your code
to get to the root of it.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
I'm having such a problem with this DropDownList in a user control that is
posting back and throwing an error: System.Web.HttpException: A
DropDownList cannot have multiple items selected

<ASP:DROPDOWNLIST ID="lbCountriesWiz" ENABLEVIEWSTATE="true"
FONT-SIZE="8pt" ONSELECTEDINDEXCHANGED="ddlQueryProvinces"
AUTOPOSTBACK="True" RUNAT="server" WIDTH="150px"></ASP:DROPDOWNLIST>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then

Dim tempItem3 As New System.Web.UI.WebControls.ListItem
tempItem3.Text = "Chad"
tempItem3.Value = "TD"
tempItem3.Selected = False
Me.lbCountriesWiz.Items.Insert(0, tempItem3)

Dim tempItem2 As New System.Web.UI.WebControls.ListItem
tempItem2.Text = "Bosnia and Herzegovina"
tempItem2.Value = "BA"
tempItem2.Selected = False
Me.lbCountriesWiz.Items.Insert(0, tempItem2)

Dim tempItem As New System.Web.UI.WebControls.ListItem
tempItem.Text = "|--None Selected"
tempItem.Value = "0"
tempItem.Selected = False
lbCountriesWiz.Items.Insert(0, tempItem)

End If

End Sub

When a button in the same user control is pushed and then I reselect the
DropDownList, I don't get the error.

<ASP:BUTTON ID="btnAllCommunities"
ONCLICK="btnPopulateAllCommunities_OnClick" FONT-SIZE="8"
RUNAT="server" TEXT="All Communities" BORDERSTYLE="inset"></ASP:BUTTON>

Public Sub btnPopulateAllCommunities_OnClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnAllCommunities.Click

'These simply fill some other listboxes

GetProvinces()
GetDistricts()
GetSubDistricts()
GetCommunities()

End Sub

When buttons (such as below) in the controling Page are pushed and then I
try to reselect the DropDownList, I get the error.

<ASP:BUTTON id="btn1" onclick="GetReport1_OnClick" RUNAT="server"
TEXT="Get report of" HEIGHT="20"
FONT-SIZE="10px"></ASP:BUTTON>

Sub GetReport1_OnClick(ByVal Sender As Object, ByVal e As
System.EventArgs)

Try

dgSHA.Visible = False
dgShasSum.Visible = False
dgCommunity.Visible = True
dgCommunitiesSum.Visible = True
ShowButtons()


'pnlCommunitiesButtons.Visible = True

Dim _sqlStmtR1 As String
_sqlStmtR1 = "SELECT * FROM vwCommunities WHERE countryID = '"
& CType(Page,
_default1).chooseAdminUnitsWiz1.lbCountriesWiz.Sel ectedItem.Value & "' "

If ddlImpactLevel1.SelectedItem.Value <> "All" Then
_sqlStmtR1 = _sqlStmtR1 & " AND Impact = '" &
ddlImpactLevel1.SelectedItem.Value & "'"
End If
'_sqlStmtR1 = _sqlStmtR1 & " ORDER BY Community"

Dim myDataSetCommunities1 As New DataSet
Dim myDataAdapterCommunities1 As New SqlDataAdapter(_sqlStmtR1,
connection1.conString)
myDataAdapterCommunities1.Fill(myDataSetCommunitie s1,
"CommunitiesTmp1")
dgCommunity.DataSource =
myDataSetCommunities1.Tables("CommunitiesTmp1")
dgCommunity.DataBind()

CommunitiesWizSqlSumStatement(1)

Dim myDataSetCommunitiesSum As New DataSet
Dim myDataAdapterCommunitiesSum As New
SqlDataAdapter(_sqlStmtLbCommunitiesWizSum, connection1.conString)
myDataAdapterCommunitiesSum.Fill(myDataSetCommunit iesSum,
"CommunitiesSumTmp1")
dgCommunitiesSum.DataSource =
myDataSetCommunitiesSum.Tables("CommunitiesSumTmp1 ")
dgCommunitiesSum.DataBind()
RecordCount2.Text = ""
RecordCount3.Text = ""
RecordCount4.Text = ""
RecordCount5.Text = ""
RecordCount6.Text = ""

Dim RcdCount As Integer
Dim ResultCount As Integer
RcdCount =
myDataSetCommunities1.Tables("CommunitiesTmp1").Ro ws.Count.ToString()
ResultCount = RcdCount
RecordCount1.Text = RcdCount & " records"
RecordCountBottom.Text = RcdCount & " records"

Session("savedDataGridSql") = _sqlStmtR1
Session("dgType") = "Community"
Me.sortCriteria = "Community"
Me.sortDir = "ASC"
If Session("dgType") = "Community" Then
pnlCommunitiesButtons.Visible = True
pnlShasButtons.Visible = False
Else
pnlCommunitiesButtons.Visible = False
pnlShasButtons.Visible = True
End If


Catch ex As Exception
ExceptionManager.Publish(ex)
End Try
End Sub

Jul 26 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
2
by: DC Gringo | last post by:
I'm having such a problem with this DropDownList in a user control that is posting back and throwing an error: System.Web.HttpException: A DropDownList cannot have multiple items selected ...
1
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. ...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
1
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in...
2
by: Lou Civitella | last post by:
I have two drop down list boxes on my asp page. The boxes store a country value on my page. They are filled by code during the load event and then I set their values in code from a table on a SQL...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
2
by: =?Utf-8?B?S3Jpc2huYQ==?= | last post by:
Hi, I am devloping one web application using .net framework 2.0.One page has 7 dropdown list control.When i update the values first bind the values to the drop down llist then selected text...
2
by: mylog | last post by:
Hi I am having a problem of getting the value from the dynamically generated table and dropdownlist. What I am facing is, I have created a table in the aspx page and now I need to add values to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.